﻿#region Includes

using System;

#endregion

namespace ArtheaEngine.Model
{
    public partial class Social : IEntity
    {
        public static bool Interpret(Character ch, Argument argument)
        {
            var arg = argument.Peek();
            /*var context = new ArtheaModel();

            foreach (var s in context.Socials)
            {
                if (!s.Name.StartsWith(arg, StringComparison.CurrentCultureIgnoreCase)) continue;

                argument.FirstArg();
                s.Parse(ch, argument);
                return true;
            }*/
            return false;
        }

        public virtual void Parse(Character ch, Argument argument)
        {
            if (argument.IsEmpty())
            {
                ch.Act(ActType.Room, OthersNoArg);
                ch.Act(ActType.Char, CharNoArg);
                return;
            }

            var victim = ch.Room.Characters.Get(c => c.Name.HasWord(argument.ToString()));

            if (victim == null)
            {
                var obj = ch.Room.Objects.Get(o => o.Name.HasWord(argument));

                if (obj == null)
                {
                    ch.WriteLine("That person or object is not here.");
                    return;
                }

                ch.Act(ActType.Char, CharObjFound, obj);
                ch.Act(ActType.Room, OthersObjFound, obj);
                return;
            }

            if (victim == ch)
            {
                ch.Act(ActType.Char, CharSelf);
                ch.Act(ActType.Room, OthersSelf);
                return;
            }

            ch.Act(ActType.Char, CharFound, victim);
            victim.Act(ActType.Char, VictFound, ch);
            victim.Act(ActType.NotChar, OthersFound, ch);
            return;
        }

        public virtual string CharFound { get; set; }

        public virtual string CharNoArg { get; set; }

        public virtual string CharNotFound { get; set; }

        public virtual string CharObjFound { get; set; }

        public virtual string CharSelf { get; set; }

        public virtual string Name { get; set; }

        public virtual string OthersFound { get; set; }
        public virtual string OthersNoArg { get; set; }
        public virtual string OthersObjFound { get; set; }
        public virtual string OthersSelf { get; set; }
        public virtual string VictFound { get; set; }
    }
}